import logging
import time
import sys
import glob
import os
sys.path.append('../../')
from framework.utils.DirUtil import *

class LogCommonUtil:
    def __init__(self,path,business):
        self.logdir = path
        self.business = business
        self.logClear()
        pass

    def logClear(self):
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        filenames = glob.glob(self.logdir+"*")
        for file in filenames:
            print(file)
            if file.find(today) < 0:
                os.remove(file)

    def writeLog(self, text):
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(self.logdir + "\\" + self.business + "_" + today + ".txt", "a")
        f.write(Log_time + text + '\n')
        f.close()